package com.cto.mode.strategy;

/**
 * @description:
 * @author: qiu
 * @param:
 * @create: 2022-03-09
 **/
public class Strategy {

	public static void main(String[] args) {
		String operator = "+";
		int a = 10;
		int b = 5;
		int result = 0;

		if ("+".equals(operator)) {
			result = add(a,b);
		} else if ("-".equals(operator)) {
			result = sub(a,b);
		} else if ("*".equals(operator)) {
			result = mul(a,b);
		} else {
			result = div(a,b);
		}

		System.out.println("结果是：" + result);

	}

	static int add(int a, int b) {
		return a + b;
	}

	static int sub(int a, int b) {
		return a - b;
	}

	static int mul(int a, int b) {
		return a * b;
	}
	static int div(int a, int b) {
		if (b == 0) throw new RuntimeException("除数不能为0");
		return a / b;
	}

}
